package com.gegong.vmware.workstation.service;


import com.gegong.vmware.workstation.VMPowerOperation;
import com.gegong.vmware.workstation.VMPowerState;
import com.gegong.vmware.workstation.exceptions.VMwareWorkstationManagementException;

/**
 * 电源管理服务
 *
 * @author dongjak
 * @version 1.0
 * @since 1.0
 */
public interface VMPowerManagementService extends VMwareWorkstationManagementService {


    /**
     * 获取指定虚拟机电源状态
     *
     * @param id 虚拟机id
     * @return
     */
    VMPowerState getPowerState(String id) throws VMwareWorkstationManagementException;


    /**
     * 操作虚拟机电源
     *
     * @param id        虚拟机id
     * @param operation 要执行的操作
     * @return {@link VMPowerState}
     */
    VMPowerState powerOperation(String id, VMPowerOperation operation) throws VMwareWorkstationManagementException;


    /**
     * 启动虚拟机
     *
     * @param id
     * @return
     */
    default VMPowerState powerOn(String id) throws VMwareWorkstationManagementException {
        return powerOperation(id, VMPowerOperation.on);
    }

    /**
     * 切断虚拟机电源
     *
     * @param id
     * @return
     */
    default VMPowerState powerOff(String id) throws VMwareWorkstationManagementException {
        return powerOperation(id, VMPowerOperation.off);
    }

    /**
     * 正常关闭虚拟机
     *
     * @param id
     * @return
     */
    default VMPowerState shutdown(String id) throws VMwareWorkstationManagementException {
        return powerOperation(id, VMPowerOperation.shutdown);
    }

    /**
     * 挂起虚拟机
     *
     * @param id
     * @return
     */
    default VMPowerState suspend(String id) throws VMwareWorkstationManagementException {
        return powerOperation(id, VMPowerOperation.suspend);
    }

    /**
     * 暂停虚拟机
     *
     * @param id
     * @return
     */
    default VMPowerState pause(String id) throws VMwareWorkstationManagementException {
        return powerOperation(id, VMPowerOperation.pause);
    }

    /**
     * 取消暂停虚拟机
     *
     * @param id
     * @return
     */
    default VMPowerState unpause(String id) throws VMwareWorkstationManagementException {
        return powerOperation(id, VMPowerOperation.unpause);
    }


    /**
     * 重启虚拟机
     * @param id
     * @return
     * @throws VMwareWorkstationManagementException
     */
    default VMPowerState restart(String id) throws VMwareWorkstationManagementException {
        shutdown(id);
        return powerOn(id);
    }

}
